<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改商户对应通道费率')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-businessRate-edit" th:object="${businessRate}">
            <input id="rateId" name="rateId" th:field="*{rateId}"  type="hidden">
			<input id="businessId" name="businessId" th:field="*{businessId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">支付类型：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="payType" class="form-control m-b" th:with="type=${@dict.getType('sys_channel_type')}">
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{payType}"></option>
						</select>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>费率(如:千分2填写0.002)：</label>
				<div class="col-sm-8">
					<input name="payRate" type="number" class="form-control required" th:field="*{payRate}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">指派码商：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="channelId">
						<option th:each="payer:${channels}" th:value="${payer.userId}" th:text="${payer.userName}" th:field="*{channelId}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3  control-label"><span style="color: red; ">*</span>码商支付类型：</label>
				<div class="col-sm-8">
					<select  id="channelPayType"  name="channelPayType" class="form-control m-b" th:with="type=${@dict.getType('sys_channel_type')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"  th:field="*{channelPayType}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3  control-label"><span style="color: red; ">*</span>码商费率(如:千分2填写0.002)：</label>
				<div class="col-sm-8">
					<input name="channelRate" type="number" class="form-control required" th:field="*{channelRate}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">指派支付商：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="payerId" id="payerId">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3  control-label"><span style="color: red; ">*</span>支付商支付类型：</label>
				<div class="col-sm-8">
					<select  id="payerPayType"  name="payerPayType" class="form-control m-b">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3  control-label"><span style="color: red; ">*</span>支付商费率(如:千分2填写0.002)：</label>
				<div class="col-sm-8">
					<input name="payerPayRate" type="number" class="form-control required" th:field="*{payerPayRate}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3  control-label"><span style="color: red; ">*</span>支付商对应商户：</label>
				<div class="col-sm-8">
					<select  id="payerBusinessId"  name="payerBusinessId" class="form-control m-b">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">最小金额：</label>
				<div class="col-sm-8">
					<input id="minAmount" type="number" name="minAmount" class="form-control" th:field="*{minAmount}">
					<div>注: -1表示金额跟随系统默认设置,大于-1表示自定义金额</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">最大金额：</label>
				<div class="col-sm-8">
					<input id="maxAmount" type="number" name="maxAmount" class="form-control" th:field="*{maxAmount}">
					<div>注: -1表示金额跟随系统默认设置,大于-1表示自定义金额</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="useStatus" th:value="${dict.dictValue}" th:field="*{useStatus}" th:checked="${dict.isDefault == 'Y' ? true : false}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">


		var prefix = ctx + "channel/businessRate";
		$("#form-businessRate-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-businessRate-edit').serialize());
	        }
	    }

		function initOptions( payerPayTypes,payerBusinessInfos, selectValue) {
			$("#payerPayType").empty();
			for(var i=0;i<payerPayTypes.length;i++){
				if(payerPayTypes[i].payerId == selectValue){
					var option = $("<option>").val(payerPayTypes[i].payType).text(payerPayTypes[i].payLabel);
					$("#payerPayType").append(option);
				}
			}
			// 支付商商户
			$("#payerBusinessId").empty();
			for(var i=0;i<payerBusinessInfos.length;i++){
				if(payerBusinessInfos[i].payerId == selectValue){
					var option = $("<option>").val(payerBusinessInfos[i].businessNo).text(payerBusinessInfos[i].businessName);
					$("#payerBusinessId").append(option);
				}
			}
		}
		var prefix = ctx + "channel/businessRate"
		var url = prefix + "/allInfo";
		$.get(url, function (data) {
			var payerPayTypes = data.data.payerPayTypes;
			var payerBusinessInfos = data.data.payerBusinessInfos;
			var payers = data.data.payers;
			// 支付商变化 对应的商户和支付类型也要变化
			$("#payerId").change(function() {
				// 支付商类型
				var selectValue = $("#payerId").val();
				initOptions( payerPayTypes,payerBusinessInfos, selectValue);
			});

			// 设置value
			var payerId = "[[${businessRate.payerId}]]";
			var payerPayType = "[[${businessRate.payerPayType}]]";
			var payerBusinessId = "[[${businessRate.payerBusinessId}]]";
			for(var i=0;i<payers.length;i++){
				var option = $("<option>").val(payers[i].userId).text(payers[i].userName);
				$("#payerId").append(option);
				if(i==0){
					initOptions( payerPayTypes,payerBusinessInfos,payerId);
				}
			}

			$("#payerId").val(payerId+"");
			$("#payerPayType").val(payerPayType+"");
			$("#payerBusinessId").val(payerBusinessId+"");
		})
	</script>
</body>
</html>
